package club.hicode.daydayup.threadlocal.demo1;

import cn.hutool.core.util.RandomUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * xx
 *
 * @author Liu Chunfu
 * @date 2018-08-09 下午5:54
 **/
public class MainStart {

    public static void main(String[] args) {

        List<String> resultList = new ArrayList<>();
        List<CommonQuery> queryList = IntStream.range(0, 3).boxed().map(i -> createInstance(i + "-"))
                .collect(Collectors.toList());

        for (CommonQuery commonQuery : queryList) {
            try {
                commonQuery.start();
                commonQuery.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


        for (CommonQuery commonQuery : queryList) {
            resultList.addAll(commonQuery.getList());
        }

        System.out.println(resultList);

    }

    private static CommonQuery createInstance(String name) {
        return new CommonQuery(name);
    }
}
